/*
 * cadCliente.java
 *
 * Created on 3 de Novembro de 2007, 16:29
 */

package cadastro;

import bd.Database;
import classes.Cliente;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author  kurumin
 */
public class cadCliente extends javax.swing.JFrame
{
    private Database bd;
    DefaultListModel telefones;
    /** Creates new form cadCliente */
    public cadCliente(Database meuBanco)
    {
        initComponents();
        c = new Cliente(meuBanco);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        telefones = new DefaultListModel();
        this.bd = meuBanco;
        preenchecombo();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" C?digo Gerado ">//GEN-BEGIN:initComponents
    private void initComponents()
    {
        grup_botao = new javax.swing.ButtonGroup();
        buttonGroup1 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        botaonome = new javax.swing.JRadioButton();
        botaocodigo = new javax.swing.JRadioButton();
        botaocpf = new javax.swing.JRadioButton();
        jLabel13 = new javax.swing.JLabel();
        jtfpesquisa = new javax.swing.JTextField();
        botaoLocalizar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtcliente = new javax.swing.JTable();
        botaoeditar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        botaoCadastrar = new javax.swing.JButton();
        botaonovo = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtfNome = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jtfRg = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        rbotaoM = new javax.swing.JRadioButton();
        rbotaoF = new javax.swing.JRadioButton();
        jLabel10 = new javax.swing.JLabel();
        jtftelefones = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jtfEmail = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jltelefones = new javax.swing.JList();
        botaoadicionar = new javax.swing.JButton();
        botaoremover = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        try
        {
            formatocpf = new MaskFormatter("###.###.###-##");
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null,"N?o foi possivel colocar maskara");
        }
        jtfcpf = new JFormattedTextField(formatocpf);
        try
        {
            formatodata = new MaskFormatter("##/##/####");
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null,"N?o foi possivel formatar a data");
        }
        jtfdatanasc = new JFormattedTextField(formatodata);
        try
        {
            formatadatac = new MaskFormatter("##/##/####");
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null,"Nao fez hehhehe");
        }
        jtfdatacad = new JFormattedTextField(formatadatac);
        jPanel8 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jtfLogradouro = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jtfBairro = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jtfCidade = new javax.swing.JTextField();
        jcbestado = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jtfCep = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(" Cadastro de Clientes");
        setResizable(false);
        jTabbedPane1.setFont(new java.awt.Font("Dialog", 0, 12));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Localizar"));
        buttonGroup1.add(botaonome);
        botaonome.setFont(new java.awt.Font("Dialog", 0, 12));
        botaonome.setText("Nome");
        botaonome.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        botaonome.setMargin(new java.awt.Insets(0, 0, 0, 0));

        buttonGroup1.add(botaocodigo);
        botaocodigo.setFont(new java.awt.Font("Dialog", 0, 12));
        botaocodigo.setSelected(true);
        botaocodigo.setText("C\u00f3digo");
        botaocodigo.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        botaocodigo.setMargin(new java.awt.Insets(0, 0, 0, 0));

        buttonGroup1.add(botaocpf);
        botaocpf.setFont(new java.awt.Font("Dialog", 0, 12));
        botaocpf.setText("CPF");
        botaocpf.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        botaocpf.setMargin(new java.awt.Insets(0, 0, 0, 0));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(48, 48, 48)
                .addComponent(botaocodigo)
                .addGap(47, 47, 47)
                .addComponent(botaonome)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 91, Short.MAX_VALUE)
                .addComponent(botaocpf)
                .addGap(56, 56, 56))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaonome)
                    .addComponent(botaocpf)
                    .addComponent(botaocodigo))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jLabel13.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel13.setText("Pesquisa.:");

        botaoLocalizar.setMnemonic('L');
        botaoLocalizar.setText("Localizar");
        botaoLocalizar.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                botaoLocalizarActionPerformed(evt);
            }
        });

        jtcliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][]
            {

            },
            new String []
            {

            }
        ));
        jScrollPane2.setViewportView(jtcliente);

        botaoeditar.setMnemonic('E');
        botaoeditar.setText("Editar");
        botaoeditar.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                botaoeditarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 397, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoeditar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jLabel13)
                        .addGap(2, 2, 2)
                        .addComponent(jtfpesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                        .addComponent(botaoLocalizar)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jtfpesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoLocalizar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 321, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoeditar)
                .addContainerGap())
        );
        jTabbedPane1.addTab("Consulta", jPanel1);

        jPanel3.setBackground(new java.awt.Color(204, 204, 204));
        jPanel3.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        botaoCadastrar.setMnemonic('G');
        botaoCadastrar.setText("Gravar");
        botaoCadastrar.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                botaoCadastrarActionPerformed(evt);
            }
        });

        botaonovo.setMnemonic('N');
        botaonovo.setText("Novo");
        botaonovo.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                botaonovoActionPerformed(evt);
            }
        });

        jButton1.setMnemonic('D');
        jButton1.setText("Deletar");
        jButton1.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(127, Short.MAX_VALUE)
                .addComponent(botaonovo, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoCadastrar)
                    .addComponent(botaonovo)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel1.setText("Nome");

        jLabel3.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel3.setText("CPF");

        jLabel4.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel4.setText("RG");

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Sexo"));
        grup_botao.add(rbotaoM);
        rbotaoM.setSelected(true);
        rbotaoM.setText("M");
        rbotaoM.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        rbotaoM.setMargin(new java.awt.Insets(0, 0, 0, 0));

        grup_botao.add(rbotaoF);
        rbotaoF.setText("F");
        rbotaoF.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        rbotaoF.setMargin(new java.awt.Insets(0, 0, 0, 0));

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(rbotaoM)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
                .addComponent(rbotaoF)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbotaoF)
                    .addComponent(rbotaoM))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jLabel10.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel10.setText("telefone");

        jLabel9.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel9.setText("Email");

        jScrollPane1.setViewportView(jltelefones);

        botaoadicionar.setMnemonic('A');
        botaoadicionar.setText("Adicionar");
        botaoadicionar.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                botaoadicionarActionPerformed(evt);
            }
        });

        botaoremover.setMnemonic('R');
        botaoremover.setText("Remover");
        botaoremover.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                botaoremoverActionPerformed(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel11.setText("Data nasc.");

        jLabel12.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel12.setText("Data cadastro");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel5Layout.createSequentialGroup()
                                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jtfRg, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(14, 14, 14)
                                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel3)
                                            .addComponent(jtfcpf, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                    .addComponent(jLabel9))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addComponent(jtfNome, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)
                            .addComponent(jtfEmail, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jtfdatacad, 0, 0, Short.MAX_VALUE)
                                    .addComponent(jtfdatanasc, 0, 0, Short.MAX_VALUE)
                                    .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel11))
                                .addGap(16, 16, 16)
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel5Layout.createSequentialGroup()
                                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE)
                                            .addComponent(jtftelefones, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(botaoremover, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(botaoadicionar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                    .addComponent(jLabel10))))
                        .addGap(46, 46, 46)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfRg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfcpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(1, 1, 1)
                        .addComponent(jLabel9))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(15, 15, 15)))
                .addGap(0, 0, 0)
                .addComponent(jtfEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoadicionar)
                    .addComponent(jtftelefones, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfdatanasc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                            .addComponent(jLabel12)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jtfdatacad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(botaoremover))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Endere\u00e7o"));
        jLabel2.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel2.setText("logradouro");

        jLabel5.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel5.setText("Bairro");

        jLabel6.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel6.setText("Cidade");

        jcbestado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AL" }));

        jLabel7.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel7.setText("UF");

        jLabel8.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel8.setText("CEP");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jtfLogradouro, javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel8Layout.createSequentialGroup()
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel5)
                                .addComponent(jtfBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel6)
                                .addComponent(jtfCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jcbestado, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel7))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel8)
                                .addComponent(jtfCep, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfLogradouro, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jcbestado, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel5, 0, 391, Short.MAX_VALUE)
                    .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jTabbedPane1.addTab("Cadastro", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-425)/2, (screenSize.height-542)/2, 425, 542);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
        String mensagem;
        if(c.deleta())
           mensagem = "Registro deletado com sucesso";
        else
           mensagem = "Erro ao tentar deletar o registro";  
        limpa();
        JOptionPane.showMessageDialog(null,mensagem);
        grava=true;
    }//GEN-LAST:event_jButton1ActionPerformed

    private void botaoeditarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaoeditarActionPerformed
    {//GEN-HEADEREND:event_botaoeditarActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
         editar();
    }//GEN-LAST:event_botaoeditarActionPerformed

    private void botaoLocalizarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaoLocalizarActionPerformed
    {//GEN-HEADEREND:event_botaoLocalizarActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        pesquisa();
    }//GEN-LAST:event_botaoLocalizarActionPerformed

    private void botaoCadastrarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaoCadastrarActionPerformed
    {//GEN-HEADEREND:event_botaoCadastrarActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        cadastrar();
    }//GEN-LAST:event_botaoCadastrarActionPerformed

    private void botaonovoActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaonovoActionPerformed
    {//GEN-HEADEREND:event_botaonovoActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        limpa();    
        grava=true;
    }//GEN-LAST:event_botaonovoActionPerformed

    private void botaoadicionarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaoadicionarActionPerformed
    {//GEN-HEADEREND:event_botaoadicionarActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        telefones.addElement(this.jtftelefones.getText());
        this.jltelefones.setModel(telefones);
        this.jtftelefones.setText("");
    }//GEN-LAST:event_botaoadicionarActionPerformed

    private void botaoremoverActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_botaoremoverActionPerformed
    {//GEN-HEADEREND:event_botaoremoverActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        telefones.remove(jltelefones.getSelectedIndex());
    }//GEN-LAST:event_botaoremoverActionPerformed
    private void cadastrar()
    {
        c.setNome(jtfNome.getText());
        c.setbairro(jtfBairro.getText());
        c.setcidade(jtfCidade.getText());
        c.setcpf(jtfcpf.getText());
        c.setdata_cad(jtfdatacad.getText());
        c.setdata_nascimento(jtfdatanasc.getText());
        c.setemail(jtfEmail.getText());
        c.setcep(jtfCep.getText());
        if(rbotaoF.isSelected())
            c.setsexo("F");
        else
            c.setsexo("M");
        c.setlogradouro(jtfLogradouro.getText());
        c.setrg(jtfRg.getText());
        c.setestado((String) jcbestado.getSelectedItem());
        c.limpatelefones();
        for(int i=0;i<jltelefones.getModel().getSize();i++){
             c.addtelefone(jltelefones.getModel().getElementAt(i).toString());
         }
       
         if(grava){
            if(c.gravar())
               mensagem = "Registro salvo com sucesso";
            else
               mensagem = "Erro ao tentar gravar o registro";
         }  
         else{
            if(c.atualizar())
               mensagem = "Registro salvo com sucesso";
            else
               mensagem = "Erro ao tentar gravar o registro";
         }
         JOptionPane.showMessageDialog(null,mensagem);
    }
    private void pesquisa()
    {
        String[] colunas = new String[]{"Codigo","Nome","CPF","Sexo"};  
        String[][] dados = new String[][]{{}};
        cliente = new DefaultTableModel(dados,colunas);
        String sql;
        ResultSet rs;
        String parametro;
        if(botaocodigo.isSelected())
            parametro = "id_cliente";
        else if(botaocpf.isSelected())
            parametro = "cpf";
        else
            parametro = "nome";
        try
        {
            sql= "SELECT cliente.id_cliente, cliente.nome, cliente.cpf, cliente.sexo FROM cliente WHERE LOWER(cliente."+parametro+") LIKE LOWER('%"+jtfpesquisa.getText()+"%')";
            rs = bd.executeQueryRs(sql);
            if(bd.Error){
                JOptionPane.showMessageDialog(null,bd.ErrorMessage);
                return;
            }
            String cli[] = new String[5];
            int aux = 0;
            while( rs.next())
            {
                cli[0] = rs.getString("id_cliente");
                cli[1] = rs.getString("nome");
                cli[2] = rs.getString("cpf");
                cli[3] = rs.getString("sexo");
                cliente.addRow(cli);     
                if (aux == 0){
                    cliente.removeRow(0);
                }
                aux++;
            }
            jtcliente.setModel(cliente);
            
        }
        catch(SQLException e)
        {
            JOptionPane.showMessageDialog(null,e);
        }
    }
    
    private void editar()
    {
         int  l = jtcliente.getSelectedRow();
         String id = jtcliente.getValueAt(l,0).toString();
         ArrayList<String> telefone = new ArrayList<String>();
         
         c.setId(id);
         c.obter();
         limpa();
         jtfBairro.setText(c.getbairro());
         jtfNome.setText(c.getNome());
         jtfCidade.setText(c.getcidade());
         jtfcpf.setText(c.getcpf());
         jtfdatacad.setText(c.getdata_cad());
         jtfdatanasc.setText(c.getdata_nascimento());
         jtfEmail.setText(c.getemail());
         jtfLogradouro.setText(c.getlogradouro());
         jtfRg.setText(c.getrg());
         jtfCep.setText(c.getcep());
         telefone = c.gettelefone();
         for(int i=0;i < telefone.size();i++)
         {
             telefones.addElement(telefone.get(i));
                 
         }
         this.jltelefones.setModel(telefones);
         jTabbedPane1.setSelectedIndex(1);
         grava=false;        
    }
    
    private void limpa()
    {
        jtfNome.setText("");
        jtfBairro.setText("");
        jtfCep.setText("");
        jtfCidade.setText("");
        jtfcpf.setText("");
        jtfdatacad.setText("");
        jtfdatanasc.setText("");
        jtfEmail.setText("");
        jtfLogradouro.setText("");
        jtfRg.setText("");
        jtftelefones.setText("");
        jtfpesquisa.setText("");
        jtftelefones.setText("");
        telefones.clear();
        this.jltelefones.removeAll();
        botaocodigo.setSelected(true);
        cliente =(DefaultTableModel) jtcliente.getModel();  
        cliente.setNumRows(0);  
    }
     private void preenchecombo()
    {
        ResultSet rs = bd.executeQueryRs("Select estado from estado");
        try {
            while (rs.next()){
                jcbestado.addItem(rs.getString(1));
                
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
   
    // Declara??o de vari?veis - n?o modifique//GEN-BEGIN:variables
    private javax.swing.JButton botaoCadastrar;
    private javax.swing.JButton botaoLocalizar;
    private javax.swing.JButton botaoadicionar;
    private javax.swing.JRadioButton botaocodigo;
    private javax.swing.JRadioButton botaocpf;
    private javax.swing.JButton botaoeditar;
    private javax.swing.JRadioButton botaonome;
    private javax.swing.JButton botaonovo;
    private javax.swing.JButton botaoremover;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup grup_botao;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JComboBox jcbestado;
    private javax.swing.JList jltelefones;
    private javax.swing.JTable jtcliente;
    private javax.swing.JTextField jtfBairro;
    private javax.swing.JTextField jtfCep;
    private javax.swing.JTextField jtfCidade;
    private javax.swing.JTextField jtfEmail;
    private javax.swing.JTextField jtfLogradouro;
    private javax.swing.JTextField jtfNome;
    private javax.swing.JTextField jtfRg;
    private javax.swing.JFormattedTextField jtfcpf;
    private javax.swing.JFormattedTextField jtfdatacad;
    private javax.swing.JFormattedTextField jtfdatanasc;
    private javax.swing.JTextField jtfpesquisa;
    private javax.swing.JTextField jtftelefones;
    private javax.swing.JRadioButton rbotaoF;
    private javax.swing.JRadioButton rbotaoM;
    // Fim da declara??o de vari?veis//GEN-END:variables
    DefaultTableModel cliente;
    private Cliente c;
    private String mensagem; 
    private boolean grava = true;
    private MaskFormatter formatocpf,formatodata, formatadatac;
}
